package com.ylbh.modules.cooperation.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylbh.common.pojo.cooperation.dto.BusinessCooperationDTO;
import com.ylbh.common.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ylbh.common.utils.PageUtils;

import com.ylbh.modules.cooperation.mapper.ShoppingBusinessCooperationMapper;
import com.ylbh.modules.cooperation.entity.ShoppingBusinessCooperation;
import com.ylbh.modules.cooperation.service.ShoppingBusinessCooperationService;


@Service("shoppingBusinessCooperationService")
public class ShoppingBusinessCooperationServiceImpl extends ServiceImpl<ShoppingBusinessCooperationMapper, ShoppingBusinessCooperation> implements ShoppingBusinessCooperationService {

    @Autowired
    private ShoppingBusinessCooperationMapper shoppingBusinessCooperationMapper;

    /**
     * 商务合作申请列表
     * @param businessCooperationDTO
     * @return
     */
    @Override
    public PageUtils queryBusinessCooperationList(BusinessCooperationDTO businessCooperationDTO) {
        Page<Integer> page = new Page<>(businessCooperationDTO.getPage(), businessCooperationDTO.getLimit());
        List<ShoppingBusinessCooperation> list = shoppingBusinessCooperationMapper.selectBusinessCooperationList(businessCooperationDTO, page);
        return new PageUtils(new Page<ShoppingBusinessCooperation>().setTotal(page.getTotal()).setRecords(list));
    }

    /**
     * 获取商务合作信息
     * @param id
     * @return
     */
    @Override
    public ShoppingBusinessCooperation getBusinessCooperationInfoId(String id) {
        ShoppingBusinessCooperation shoppingBusinessCooperation = shoppingBusinessCooperationMapper.selectById(id);
        // 如果状态未于待处理状态，则修改成已查阅
        if (shoppingBusinessCooperation.getHandleState() == 0) {
            ShoppingBusinessCooperation dto = new ShoppingBusinessCooperation();
            dto.setId(shoppingBusinessCooperation.getId());
            dto.setHandleState(1);
            dto.setHandleTime(new Date());
            dto.setSysUserId(ShiroUtils.getUserId().toString());
            shoppingBusinessCooperationMapper.updateById(dto);
        }
        return shoppingBusinessCooperation;
    }
}
